Skip to content

Add type validations for function imports#8478

Merged
stevenfontanella merged 2 commits intomainfrom
function-type-validation
Mar 18, 2026
Merged

Add type validations for function imports#8478
stevenfontanella merged 2 commits intomainfrom
function-type-validation

Conversation

@stevenfontanella
Copy link
Member

@stevenfontanella stevenfontanella commented Mar 17, 2026

Validates that the exported function is a subtype of the import declaration. Part of #8261.

Example error:

(module $A
  (func $f (export "f") (param i32) (result i32)
    (local.get 0)
  )
)

(register "A" $A)

(module $B
  (func (import "A" "f") (result i32))
)

;; [trap Imported function A.f with type (func (param i32) (result i32)) isn't compatible with import declaration with type (modulo rec groups): (func (result i32))]

@stevenfontanella stevenfontanella changed the title Add validations for function imports Add type validations for function imports Mar 17, 2026
@stevenfontanella stevenfontanella marked this pull request as ready for review March 17, 2026 21:46
}

if (auto** tableDecl = std::get_if<Table*>(&import)) {
} else if (auto** tableDecl = std::get_if<Table*>(&import)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-up, it would be nice to give Importable a getKind method so we could use a switch here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use std::visit or switch on import.index() if that sounds good? I didn't use visit originally since there are a lot of variables that we'd have to capture from the outside. Is the idea to make the cases exhaustive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, to make it exhaustive and to make it easier to read (although that's subjective). I guess we would still need to cast to the relevant subtype, though, so maybe it's not worth it.

@stevenfontanella stevenfontanella enabled auto-merge (squash) March 18, 2026 17:58
@stevenfontanella stevenfontanella merged commit 0f06b26 into main Mar 18, 2026
16 checks passed
@stevenfontanella stevenfontanella deleted the function-type-validation branch March 18, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants